<%@page import="com.polytech.model.Post"%>
<%@page import="com.polytech.model.Topic"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <meta charset="utf-8">
    <title>
       <% Topic topic=(Topic)request.getAttribute("topic");%>
       <%=topic.getSubject()%>
    </title>
 
    <link href="/irm-forum/views/css/css.css" rel="stylesheet">
    <link href="/irm-forum/views/css/main.css" rel="stylesheet">
	<link href="/irm-forum/views/css/table.css" rel="stylesheet">
  </head>
  <body>
	<jsp:include page="layout/header.jsp"/>
    <div class="wrapper">
      <div class="content">
      <% if(session.getAttribute("login")==null){ %>
     	 <div align="right">
     	   <p> <a href="/irm-forum/profile/login.action"> Connectez vous pour publier vos questions </a> </p>
         </div>
      <%} %>
        <table>
          <thead>
            <tr>
              <th colspan="2" style="text-align: left;">
              	<span style="position: relative;left: 0px;">Sujet: <%=topic.getSubject()%></span>
              	<span style="position: relative;left:30%">poster le <%=topic.getPublicationDate() %> par <%=topic.getCreator().getLogin() %> </span>
              </th>
            </tr>
          </thead>
    	  <tbody>
     	    <tr class="alt">
      		  <td colspan="2" style="height: 50px;padding: 5p;overflow: auto;"><%=topic.getText()%></td>
      		</tr>
      		<%
      		if(topic.getPosts()!=null)
      		for(Post post:topic.getPosts()){%>
      		<tr>
      		  <td style="width:15%;text-align: center;"> <%=post.getPoster().getLogin()%></td>
      		   <td style="padding: 5px;"> <%=post.getText()%>  </td>
      		</tr>
      		<%}%>
      	  </tbody>
      	  </table>
      	    <%
      	      if(session.getAttribute("login")!=null){
      	    %>
      	      <form method="post" action="/irm-forum/forum/new-post.action">
      	      	 <input type="hidden"  name="id" value="<%=topic.getId()%>">
          		 <table>
          		   <tr>
          		     <td> <textarea rows="3" cols="113" name="text"></textarea> </td>
          		   </tr>
          		   <tr>
          		     <td align="right"> <input type="submit" value="Publier" class="button"> </td>
          		   </tr>
          		 </table>
        	 </form>
      	    <%}%>
      </div>
    </div>
   <jsp:include page="/views/layout/footer.jsp"></jsp:include>
       
</body></html>